using UnityEngine;
using QFramework;

namespace ProjectSurvivor
{
	public partial class SimpleAex : ViewController//表示一个挂在场景物体上的控制器（如玩家、刷怪器）。
	{
		void Start()
		{
			// Code Here
		}
		private float mCurrentSecounds = 0;
		void Update()
		{
			mCurrentSecounds += Time.deltaTime;
			if (mCurrentSecounds >= 1f)
			{
				Aex.Instantiate()
				.Show().
				Position(this.Position()).
				Self(self =>
				{

					var rigidbody2D = self.GetComponent<Rigidbody2D>();
					var randomX = RandomUtility.Choose(-8, -5, -3, 3, 5, 8);
					var randomY = RandomUtility.Choose(3, 5, 8);
					rigidbody2D.velocity = new Vector2(randomX, randomY);
					self.OnTriggerEnter2DEvent(collider =>
					{
						var HurtBox = collider.GetComponent<HurtBox>();
						if (HurtBox)
						{
							if (HurtBox.Owner.GetComponent<Enemy>())
								{
									DamageSystem.CalculateDamage(Global.SimpleAbilityDamage.Value, HurtBox.Owner.GetComponent<Enemy>());
								}
								else
								{
									DamageSystem.CalculateDamage(Global.SimpleAbilityDamage.Value, HurtBox.Owner.GetComponent<EnemyMinBoss>());
								}
						}
					}).UnRegisterWhenGameObjectDestroyed(self);
					ActionKit.OnUpdate.Register(()=>//注册帧更新/UI调试回调；
					{
						if (Player.Default&&Player.Default.Position().y - self.Position().y > 15)
						{
							self.DestroyGameObjGracefully();
						}
					}).UnRegisterWhenGameObjectDestroyed(self);
				});
				mCurrentSecounds = 0;
			}
        }
    }
}
